<template>
  <div>
    <el-form ref="form" :model="form" label-width="207px">
      <el-form-item label="分类挂件显示">
        <el-radio-group v-model="form.isDisplay" size="medium">
          <el-radio label="1" border>是</el-radio>
          <el-radio label="0" border>否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="分类挂件类型">
        <el-radio-group v-model="form.type" size="medium">
          <el-radio-button label="course">课程分类</el-radio-button>
          <el-radio-button label="class">班级分类</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="分类挂件背景透明">
        <el-radio-group v-model="form.isTransparency" size="medium">
          <el-radio label="1" border>是</el-radio>
          <el-radio label="0" border>否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="移动端banner图单独上传">
        <el-radio-group v-model="form.separatelyUpload" size="medium">
          <el-radio label="1" border>是</el-radio>
          <el-radio label="0" border>否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="updatePageConfig">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getPageConfig, updatePageConfig } from '@/api/operate/zerotheme' // 数据接口
import { getTenantId, getUserId, getUserName } from '@/utils/auth'
export default {
  data() {
    return {
      form: {
        isDisplay: '1',
        isTransparency: '1',
        separatelyUpload: '1',
        type: 'course'
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {
    getData() {
      getPageConfig(getTenantId()).then(response => {
        if (response.data.item) {
          this.form = response.data.item
          this.form.isDisplay = response.data.item.isDisplay.toString()
          this.form.isTransparency = response.data.item.isTransparency.toString()
          this.form.separatelyUpload = response.data.item.separatelyUpload.toString()
          this.form.type = response.data.item.type.toString()
        }
      })
    },
    updatePageConfig() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.form.userId = getUserId()
          this.form.userName = getUserName()
          this.form.tenantId = getTenantId()
          updatePageConfig(this.form).then(response => {
            this.$notify({
              title: '成功',
              message: '保存成功！',
              type: 'success',
              duration: 2000
            })
          })
        } else {
          this.$message.success('保存失败！')
          return false
        }
      })
    }
  }
}
</script>
